#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;

int n;
int m[N], a[N];
pii b[N];

ll fastpow(ll b, ll p) {
  ll res = 1;
  while (p) {
    if (p & 1) res = res * b % MOD;
    b = b * b % MOD;
    p >>= 1;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> m[i];
  rep(i, 1, n) cin >> a[i];
  int mnr = 1e9;
  rep(i, 1, n) {
    int l = a[i] - 1, r = m[i] - a[i];
    if (l > r) swap(l, r);
    b[i] = pii(l, r);
    mnr = min(mnr, r);
  }
  sort(b + 1, b + n + 1);
  ll sum = 0;
  rep(i, 1, n) {
    if (b[i].first > mnr) {
      sum = (sum + mnr * fastpow(2, n + 1 - i) % MOD) % MOD;
      break;
    } else {
      sum = (sum + b[i].first * fastpow(2, n - i) % MOD) % MOD;
    }
  }
  if (b[n].first <= mnr) sum = (sum + mnr) % MOD;
  cout << sum + 1;
  return 0;
}